package com.hpeu_01.day0126.homework;

import java.lang.reflect.Constructor;

/**
 * 第三题：利用反射和重载完成以下功能
 * 1.创建Student类，类中有属性name和age并封装属性
 * 2.重载Student的构造函数，一个是无参构造，另一个是带两个参数的有参构造，要求在构造函数打印提示信息
 * 3.创建main函数，利用Class类得到Student对象
 * 4.通过上述获取的Class对象分别调用Student有参函数和无参函数。
 */
public class Test01 {
    public static void main(String[] args) throws Exception {
        Class<Student> clazz = Student.class;
        Object student = clazz.newInstance();
        System.out.println(student);
        Constructor<Student> constructor = clazz.getDeclaredConstructor(String.class, Integer.class);
        Object student1 = constructor.newInstance("ss",1);
        System.out.println(student1);
    }
}
class Student{
    private String name;
    private Integer age;

    public Student() {
        System.out.println("无参构造器");
    }

    public Student(String name, Integer age) {
        this.name = name;
        this.age = age;
        System.out.println("有参构造器");
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}